import React from 'react'
import './index.scss'
export default function MyCount({ count, changeCount, id }) {
  const handleDecrease = () => {
    // !#2. 子组件调用传递过来的方法并传递实参
    if (count <= 1) return
    changeCount(id, count - 1)
  }
  const handleIncrease = () => {
    changeCount(id, count + 1)
  }
  return (
    <div className='my-counter'>
      <button type='button' className='btn btn-light' onClick={handleDecrease}>
        -
      </button>
      <input
        type='number'
        className='form-control inp'
        value={count}
        onChange={() => {}}
      />
      <button type='button' className='btn btn-light' onClick={handleIncrease}>
        +
      </button>
    </div>
  )
}
